home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January
/
CHIP_CD_01_2007.iso
/
Hity z okladki
/
OrgPlus 6 SBE
/
ORGPL.CAB
/
listCtrl.js
< prev
next >
Wrap
Text File
|
2006-09-20
|
8KB
|
326 lines
var g_currentID = 1;
var LCF_SHOWCAPTURE = 1;
var LCF_HIGHLIGHT = 2;
var LCF_SHOWGRID = 4;
var LCF_DEFAULT = LCF_HIGHLIGHT;
function ListCtrl( p_oParentElement )
{
this.Create = _ListCtrl_Create;
this.Add = _ListCtrl_Add;
this.Remove = _ListCtrl_Remove;
this.GetStyle = _ListCtrl_GetStyle;
this.RemoveAll = _ListCtrl_RemoveAll;
this.AddColumn = _ListCtrl_AddColumn;
this.RemoveColumn = _ListCtrl_RemoveColumn;
this.ClearTable = _ListCtrl_ClearTable;
this.Show = _ListCtrl_Show;
this.SetWidth = _ListCtrl_SetWidth;
this.ShowGrid = _ListCtrl_ShowGrid;
this.Columns = new Array();
this.ID = g_currentID++;
this.Style = LCF_DEFAULT;
this.table = null;
this.RowsCount = 0;
this.ColumnsCount = 0;
this._parent = null;
this.HighlightColor = "#eeeeee";
if( typeof(p_oParentElement) == 'undefined' )
this.Create( p_oParentElement );
};
function ListCtlColumn( p_sColumnCapture, p_iWidth )
{
if( typeof(p_iWidth) == 'undefined' || p_iWidth == null )
p_iWidth = 100;
this.SetWidth = function( p_iWidth){ this.Width = p_iWidth; };
this.Capture = p_sColumnCapture;
this.ID = g_currentID++;
this.Width = p_iWidth;
this.Cells = new Array();
this.CellsCount = 0;
};
function ListCtlCell( p_sValue, p_iColumnsCount )
{
if( typeof(p_iColumnsCount) == 'undefined' || p_iColumnsCount == 0 || p_iColumnsCount < 1 )
p_iColumnsCount = 1;
this.Value = p_sValue;
this.ColumnsCount = p_iColumnsCount;
}
function _ListCtrl_Create( p_oParentElement )
{
if( typeof( p_oParentElement ) == 'undefined' )
return;
this.table = document.createElement("<table width='100%'></table>");
p_oParentElement.appendChild( this.table );
// this.table.width = "100%";
this.table.style.zIndex = 0;
this.table.cellSpacing = 0;
this.table.cellpadding = 0;
this.table.style.backgroundColor = "transparent";
this._parent = p_oParentElement;
if( this.ColumnsCount > 0 && this.RowsCount > 0 )
this.Show();
}
function _ListCtrl_Add( p_oObj )
{
if( typeof( p_oObj ) == 'undefined' || p_oObj == null )
return;
for( i = 0; i < this.Columns.length; ++i )
{
var pVal = " ";
var iColumnsCount = 1;
if( typeof(p_oObj[i]) != 'undefined' )
{
pVal = p_oObj[i];
iColumnsCount = p_oObj[i].ColumnsCount;
}
this.Columns[i].Cells[ this.Columns[i].CellsCount ] = pVal;
this.Columns[i].CellsCount++;
for( var t=i+1; (t < this.Columns.length)&&((t-i) < iColumnsCount); ++t )
{
var o = new ListCtlCell( "", 1);
o.Empty = true;
this.Columns[t].Cells[ this.Columns[t].CellsCount ] = o;
this.Columns[t].CellsCount++;
}
i = t - 1;
};
++this.RowsCount;
}
function _ListCtrl_Remove()
{
throw "not implement";
}
function _ListCtrl_ShowGrid( p_bFlag )
{
if( typeof(p_bFlag) == 'undefined' )
p_bFlag = true;
if( p_bFlag == true )
{
this.Style |= LCF_SHOWGRID;
}
else if( p_bFlag == false )
{
this.Style &= ~LCF_SHOWGRID;
}
}
function _ListCtrl_GetStyle()
{
return this.Style;
}
function _ListCtrl_RemoveAll()
{
for( i = 0; i < this.Columns.length ; ++i)
{
var oColumn = this.Columns[ i ];
for( ; oColumn.CellsCount > 0; )
{
oColumn.Cells[ oColumn.CellsCount ] = null;
oColumn.CellsCount--;
}
};
this.RowsCount = 0;
}
function _ListCtrl_AddColumn( p_sColumnCapture, p_iColumnWidth )
{
var oNewColumn = new ListCtlColumn( p_sColumnCapture, p_iColumnWidth );
this.Columns[ this.ColumnsCount ] = oNewColumn;
this.ColumnsCount++;
for( i = 0; i < this.RowsCount; ++i )
{
oNewColumn.Cells[oNewColumn.CellsCount] = new ListCtlCell("", 1);
oNewColumn.CellsCount++;
}
}
function _ListCtrl_RemoveColumn()
{
throw "not implement";
}
function GetCellAbsolutePosition( p_oCell )
{
var iOffsetLeft = p_oCell.offsetLeft;
var iOffsetTop = p_oCell.offsetTop;
var oParentElement = p_oCell.parentElement;
while( oParentElement != null )
{
if( oParentElement.tagName == "CENTER" || oParentElement.tagName == "TD" )
{
iOffsetLeft += oParentElement.offsetLeft;
oParentElement = oParentElement.parentElement;
continue;
}
iOffsetLeft += oParentElement.offsetLeft;
iOffsetTop += oParentElement.offsetTop;
oParentElement = oParentElement.parentElement;
}
var obj = new Object();
obj.x = iOffsetLeft;
obj.y = iOffsetTop;
return obj;
}
function _ListCtrl_Show()
{
if( typeof(this.table) == 'undefined' || this.table == null )
return;
this.ClearTable();
for( iIndex = 0; iIndex < this.RowsCount; ++iIndex )
this.table.insertRow( iIndex );
var iOffset = 0;
if( this.GetStyle() & LCF_SHOWCAPTURE )
{
var oCaptureRow = this.table.insertRow(0);
for( var i = 0; i < this.ColumnsCount; ++i )
{
var oCell = oCaptureRow.insertCell(oCaptureRow.cells.length);
oCell.innerHTML = "<NOBR>" + this.Columns[i].Capture + "</NOBR>";
}
iOffset = 1;
};
if( this.Style & LCF_SHOWGRID )
{
this.table.style.borderRight = "gray 1px solid";
this.table.style.borderBottom = "gray 1px solid";
}
else
{
this.table.style.borderRight = "gray 0px solid";
this.table.style.borderBottom = "gray 0px solid";
}
for(iCurrentRow = 0; iCurrentRow < this.RowsCount; ++iCurrentRow )
{
var oRow = this.table.rows[iCurrentRow + iOffset];
for( iIndex = 0; iIndex < this.ColumnsCount; ++iIndex )
{
var oColumn = this.Columns[iIndex];
var sCellValue = oColumn.Cells[iCurrentRow].Value;
if( oColumn.Cells[iCurrentRow].Empty == true )
continue;
var oCell = oRow.insertCell( iIndex );
oCell.innerHTML = sCellValue;
oCell.width = oColumn.Width;
oCell.style.cellPadding = 1;
oCell.style.cellSpacing = 1;
if( this.Style & LCF_SHOWGRID )
{
oCell.style.borderLeft = "gray 1px solid";
oCell.style.borderTop = "gray 1px solid";
}
if( oCell.children.length > 0 )
{
oCell.style.backgroundColor = oCell.children[0].currentStyle.backgroundColor;
oCell.style.textAlign = oCell.children[0].currentStyle.textAlign;
oCell.style.verticalAlign = oCell.children[0].currentStyle.verticalAlign;
oCell.children[0].style.backgroundColor = "";
}
oCell.listCtrl = this;
oCell.colSpan = oColumn.Cells[iCurrentRow].ColumnsCount;
oCell.style.zIndex = 2;
if( this.GetStyle() & LCF_HIGHLIGHT )
{
oCell.onmouseenter = HighlightCell;
oCell.onmouseleave = UnhighlightCell;
}
}
}
}
function HighlightCell()
{
var oCell = event.srcElement;
var oRow = oCell.parentElement;
for( i = 0; i < oRow.cells.length; ++i )
{
oCell = oRow.cells[i];
oCell._oldBgColor = oCell.style.backgroundColor;
oCell.style.backgroundColor = oCell.listCtrl.HighlightColor;
};
};
function UnhighlightCell()
{
var oCell = event.srcElement;
var oRow = oCell.parentElement;
for( i = 0; i < oRow.cells.length; ++i )
{
oCell = oRow.cells[i];
oCell.style.backgroundColor = oCell._oldBgColor;
};
}
function _ListCtrl_ClearTable()
{
if( typeof(this.table) == 'undefined' || this.table == null )
return;
for( ; this.table.rows.length > 0; )
{
var oRow = this.table.rows[this.table.rows.length - 1];
for(; oRow.cells.length > 0; )
oRow.deleteCell(0);
this.table.deleteRow(0);
}
};
function _ListCtrl_SetWidth( p_iColumnIndex, p_sWidth )
{
if( typeof(this.table) == 'undefined' || this.table == null )
return;
if( p_iColumnIndex == null || p_sWidth == null )
return;
var oRow = this.table.rows[0];
if( oRow == null || oRow.cells[p_iColumnIndex] == null )
return;
oRow.cells[p_iColumnIndex].width = p_sWidth;
};